package com.ruoyi.controller;

import com.jnxx.basic.util.AjaxResult;
import com.ruoyi.pojo.tools.ImageTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;

@RestController
@RequestMapping("/system/image")
public class ImageController {
    
    @Autowired
    private ImageTool imageTool;

    /*图片上传*/
    @PostMapping(value = "/upLoad", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public AjaxResult uploadFile(@RequestPart("file") MultipartFile uploadfile) {
        AjaxResult ajaxResult = imageTool.uploadFile(uploadfile);
        Object data = ajaxResult.getData();
        return AjaxResult.success(data.toString());
    }
    
    /**
     * 根据图片名称删除图片
     * @param map
     * @return
     */
    @PostMapping(value = "/delProductPicture")
    public AjaxResult delProductPicture(@RequestBody HashMap<String, String> map) {
        String path = map.get("path");
        imageTool.delProductPicture(path);
        return AjaxResult.success();
    }
    
}
